package com.hospital.register.vo.core.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Comparator;
import java.util.Date;

@Data
@ApiModel(description = "每天的排班数据")
public class ScheduleDayVo {

    /**
     * 就诊医生人数的 key
     */
    public static final String DOC_COUNT = "docCount";


    @ApiModelProperty(value = "可预约日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date workDate;

    @ApiModelProperty(value = "可预约日期")
    @JsonFormat(pattern = "MM月dd日")
    private Date workDateMd; //方便页面使用

    @ApiModelProperty(value = "周几")
    private String dayOfWeek;

    @ApiModelProperty(value = "就诊医生人数")
    private Integer docCount;

    @ApiModelProperty(value = "科室剩余预约数")
    private Integer reservedNumber;

    @ApiModelProperty(value = "科室可预约数")
    private Integer availableNumber;

    @ApiModelProperty(value = "状态 0：正常 1：即将放号 -1：当天已停止挂号")
    private Integer status;

    /**
     * 比较排班日期
     */
    private static WorkDateComparator workDateComparator = new WorkDateComparator();

    /**
     * 返回排班日期的比较器
     *
     * @return 排班日期比较器
     */
    public static WorkDateComparator getWorkDateComparator() {
        return ScheduleDayVo.workDateComparator;
    }

    /**
     * 比较排班日期
     *
     * @author 刘逸晖
     */
    private static class WorkDateComparator implements Comparator<ScheduleDayVo> {

        /**
         * 对两个排班日期进行比较
         *
         * @param schedule1 第一个排班
         * @param schedule2 第二个排班
         * @return 比较结果
         */
        @Override
        public int compare(ScheduleDayVo schedule1, ScheduleDayVo schedule2) {
            if (schedule1 == null || schedule1.getWorkDate() == null ||
                    schedule2 == null || schedule2.getWorkDate() == null) {
                throw new IllegalArgumentException("排班以及其中的日期不可为空");
            }

            return Long.compare(schedule1.getWorkDate().getTime(), schedule2.getWorkDate().getTime());
        }
    }

}

